package com.cskaoyan._01getclass;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/14 14:23
 **/

public class Demo {
    public static void main(String[] args) {
        //test();
        // 方法声明
        // public final native Class<?> getClass();

        Student s1 = new Student("zs", 20);
        Class c1 = s1.getClass();
        System.out.println("c1.getName() = " + c1.getName());
        System.out.println("c1.getSimpleName() = " + c1.getSimpleName());

        Student s2 = new Student("ls", 21);
        Class c2 = s2.getClass();
        //作用: 可以判断对象的类型是否相同
        System.out.println(c1 == c2);

        Teacher t = new Teacher();
        Class c3 = t.getClass();
        System.out.println(c1 == c3);

        System.out.println("-------------");
        boolean b = judgeObjectType(s1, s2);
        System.out.println(b);
        boolean b1 = judgeObjectType(s1, t);
        System.out.println(b1);

        SonTeacher sonTeacher = new SonTeacher();
        boolean b2 = judgeObjectType(t, sonTeacher);
        System.out.println(b2);

    }

    // 判断对象所属类型 跟继承没关系
    public static boolean judgeObjectType(Object o1, Object o2) {
        return o1.getClass() == o2.getClass();
    }

    // 意味着这个方法过时了
    @Deprecated
    public static void test() {

    }
}

class Student{
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

class Teacher{

}

class SonTeacher extends Teacher{

}